package com.hsj.springcloud.controller;

import com.hsj.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

/**
 * @author:Teacher黄
 * @date:Created at 2019/07/29
 */
@RestController
public class ConsumerController {

    @Autowired
    private RestTemplate restTemplate;


    @GetMapping("/ribbon/consumer")
    public String helloConsumer(){
        return restTemplate.getForEntity("http://HELLO-SERVICE/hello", String.class).getBody();
    }

    @GetMapping("/ribbon/user")
    public User userConsumer(){
        System.out.println("gitee");
        Map<String,String> params = new HashMap<>(16);
        params.put("userName","hsj");
        params.put("userAge","11");
        return restTemplate.getForObject("http://HELLO-SERVICE/user?userName={userName}&userAge={userAge}",User.class,params);
    }


}
